package com.zretc.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.zretc.entity.Users;

/**
 * @RestController 请求响应结果为满足ajax的json字符串
 * @author Administrator
 *
 */
@RestController
public class UsersRestController {

	// 注入一个Users对象
	@Autowired
	private Users u;

	/**
	 * 返回值类型是 String
	 * 
	 * @param id
	 * @return
	 */
	@GetMapping(value = "users", produces = "application/json;charset=utf-8")
	public String getUsersById(int id) {
		return u.toString();
	}

	
	/**
	 * 类前面有@RestController
	 * 返回值类型 Users对象,返回格式要满足json格式字符串
	 *  produces = "application/json
	 *  可以使用jackson的jar包组合.
	 * @param id
	 * @return
	 */
	@GetMapping(value = "users2", produces = "application/json;charset=utf-8")
	public Users getUsersById2(int id) {
		return u;
	}
	
	
}
